package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.CompaniesRankEntity;
import com.runen.infinitemovement.tool.CommonUtil;
import com.runen.infinitemovement.tool.GlideUtils;
import com.runen.infinitemovement.widget.imageview.RoundedCornersImage;

import java.util.List;

public class HomeTeamProgressAdapter extends BaseQuickAdapter<CompaniesRankEntity, BaseViewHolder> {
    private Context context;

    public HomeTeamProgressAdapter(Context context) {
        super(R.layout.item_home_team_progress);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CompaniesRankEntity item) {
        LinearLayout ll_home_team_progress_info = helper.getView(R.id.ll_home_team_progress_info);
        ImageView iv_team_ranking = helper.getView(R.id.iv_team_ranking);
        TextView tv_team_ranking = helper.getView(R.id.tv_team_ranking);
        RoundedCornersImage rci_team_logo = helper.getView(R.id.rci_team_logo);
        TextView tv_team_name = helper.getView(R.id.tv_team_name);
        TextView tv_team_progress = helper.getView(R.id.tv_team_progress);
        int position = helper.getAdapterPosition();
        if (position < 9) {
            tv_team_ranking.setText("0" + (position + 1));
        } else {
            tv_team_ranking.setText((position + 1));
        }
        if (position % 2 == 0) {
            ll_home_team_progress_info.setBackgroundColor(CommonUtil.getColor(R.color.color_1AF9F8F9));
        } else {
            ll_home_team_progress_info.setBackgroundColor(CommonUtil.getColor(R.color.colorTransparent));
        }
        switch (position) {
            case 0:
                iv_team_ranking.setImageResource(R.mipmap.ico_ranking1);
                break;
            case 1:
                iv_team_ranking.setImageResource(R.mipmap.ico_ranking2);
                break;
            case 2:
                iv_team_ranking.setImageResource(R.mipmap.ico_ranking3);
                break;
        }
        GlideUtils.loadImage(context, item.logo + "?x-oss-process=image/resize,m_fill,w_144,h_144", rci_team_logo);
        tv_team_name.setText(item.name);
        tv_team_progress.setText(CommonUtil.Double2position(item.progress * 100) + "%");
    }
}
